NOTE: This Technical Note has been retired. Please see the Technical Notes page for current documentation.

Technical Note TE17
TextEdit Conversion Utility

CONTENTS

Text sometimes must be converted between a Pascal string and "pure" text in a handle. This note illustrates a way to do this using MPW Pascal.

[Mar 01 1988]






Introduction

Text contained in TextEdit records sometimes must be passed to routines which expect a Pascal string of type Str255 (a length byte followed by up to 255 characters). The following MPW Pascal unit can be used to convert between TextEdit records and Pascal strings:

    UNIT TEConvert;

       {General utilities for conversion between TextEdit and strings}

       INTERFACE

          USES MemTypes,QuickDraw,OSIntf,ToolIntf;

          PROCEDURE TERecToStr(hTE: TEHandle; VAR str: Str255);
          {TERecToStr converts the TextEdit record hTE to the string str.}
          {If necessary, the text will be truncated to 255 characters.}

          PROCEDURE StrToTERec(str: Str255; hTE: TEHandle);
          {StrToTERec converts the string str to the TextEdit record hTE. }

       IMPLEMENTATION

          PROCEDURE TERecToStr(hTE: TEHandle; VAR str: Str255);

             BEGIN
                GetIText(hTE^^.hText, str);
             END;

          PROCEDURE StrToTERec(str: Str255; hTE: TEHandle);

             BEGIN
                TESetText(POINTER(ORD4(@str) + 1), ORD4(length(str)), hTE);
             END;


Back to top

References

Macintosh Memory Management: An Introduction TextEdit

Back to top

Downloadables

Acrobat gif

Acrobat version of this Note (40K).

Download



Developer Documentation | Technical Q&As | Development Kits | Sample Code